import java.util.Arrays;

/**
 * Created by cc
 * Description:
 * User: CZH
 * Date: 2022-09-12
 * Time: 14:33
 */
public class Test01 {



    public static int[] my_copyOf(int[] arr, int len) {
        int[] newArr = new int[len];
        for (int i = 0; i < len; i++) {
            newArr[i] = arr[i];
        }
        return newArr;
    }
    public static void main(String[] args) {
        int[] arr1 = {1,2,3,4,5,6,7,8,9};
        int[] arr2 = my_copyOf(arr1, arr1.length);
        System.out.println(Arrays.toString(arr2));
    }



    public static void main10(String[] args) {
        int[] arr1 = {1,2,3,4,5,6,7,8,9};
        int[] arr2 = Arrays.copyOfRange(arr1, 2,4);
        System.out.println(Arrays.toString(arr2));
    }


    //
    public static void main9(String[] args) {
        int[] arr1 = {1,2,3,4,5,6};
        int[] arr2 = Arrays.copyOf(arr1, arr1.length);
        System.out.println("arr2:" + Arrays.toString(arr2));

        arr1[0] = 199;
        System.out.println("arr1:" + Arrays.toString(arr1));
        System.out.println("arr2:" + Arrays.toString(arr2));
    }



    //
    public static String my_toString(int[] arr) {
        String str = "[";
        for (int i = 0; i < arr.length - 1; i++) {
            str += (arr[i] + ", ");
        }
        str += (arr[arr.length - 1] + "]");
        return str;
    }
    public static void main8(String[] args) {
        int[] arr = {1,2,3,4,5,6};
        String string = my_toString(arr);
        System.out.println(string);
    }


    //
    public static void main7(String[] args) {
        int[] arr = {1,2,3};
        int[] arr2 = transform(arr);
        printArray(arr);
        printArray(arr2);

    }
    public static int[] transform(int[] arr1) {
        int[] arr2 = new int[arr1.length];
        for (int i = 0; i < arr1.length; i++) {
            arr2[i] = (arr1[i] * 2);
        }
        return arr2;
    }
    public static void printArray(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
    }



    //
    public static void main6(String[] args) {
        int[] arr = {1,2,3};
        func2(arr);
        System.out.println(arr[0]);
    }
    public static void func2(int[] a){
        a[0] = 10;
        System.out.println(a[0]);
    }


    //
    public static void main5(String[] args) {
        int num = 0;
        func1(num);
        System.out.println(num);
    }
    public static void func1(int x){
        x = 10;
        System.out.println(x);
    }



    //4次 / 7.99
    //5次 / 5.99-=
    //3.5次 / 3.99
    //
//    public static void printArr(int[] arr) {
//        for (int x : arr) {
//            System.out.println(x);
//        }
//    }
//    public static void main(String[] args) {
//        int[] arr = {1,2,3};
//        printArr(arr);
//    }


    public static void main3(String[] args) {
        int[] arr = {1,2,3,4};
        for (int x : arr) {
            System.out.println(x);
        }
    }


    public static void main2(String[] args) {
        int[] arr = {1,2,3,4};
        for (int i = 0; i < arr.length; i++){
            System.out.println(arr[i]);
        }
    }


    public static void main1(String[] args) {
        int[] arr = {1,2,3};
        //获取数组长度 -> 3
        System.out.println("length:" + arr.length);

        //访问数组中的元素
        System.out.println(arr[1]); //2
        System.out.println(arr[0]); //1
        arr[1] = 199;
        System.out.println(arr[1]); //199
    }
}
